<?php

namespace app\front\controller;

use app\common\exception\BaseException;
use app\JjjController;
use think\facade\View;
use app\front\model\menu\Menu as MenuModel;
use app\common\model\settings\Setting as SettingModel;
use app\front\model\link\Link as LinkModel;
use think\facade\Request;

/**
 * API控制器基类
 */
class Controller extends JjjController
{
    // app_id
    protected $app_id;

    /**
     * 后台初始化
     */
    public function initialize()
    {
        // 当前小程序id
        $this->app_id = 10001;
        $data = Request::param();
        //导航
        $menuList = MenuModel::getHomeMenu($data);
        //网站设置
        $sysConfig = SettingModel::getItem('store', $this->app_id);
        if ($sysConfig['web_status'] == 1) {
            if($sysConfig['close_url']){
                header("Location: ".$sysConfig['close_url']);exit;
            }
            die("<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>网站暂时关闭，维护中……</div>");
        }
        //其它设置
        $otherConfig = SettingModel::getItem('other', $this->app_id);
        $otherConfig['coordinate'] = explode(',', $otherConfig['coordinate']);
        $otherConfig['lat'] = isset($otherConfig['coordinate'][0]) ? $otherConfig['coordinate'][0] : 0;
        $otherConfig['lng'] = isset($otherConfig['coordinate'][1]) ? $otherConfig['coordinate'][1] : 0;
        //其它设置
        $linkList = (new LinkModel)->getLists();
        //底部数据
        $footerData = (new MenuModel())->getFooterData();
        //当前方法
        $method = Request()->controller();
        View::assign('menuList', $menuList);
        View::assign('sysConfig', $sysConfig);
        View::assign('otherConfig', $otherConfig);
        View::assign('linkList', $linkList);
        View::assign('method', $method);
        View::assign('footerData', $footerData);
    }

}
